package com.liuyk.activity;

import android.os.Bundle;
import android.transition.ChangeBounds;
import android.transition.ChangeTransform;
import android.transition.Fade;
import android.transition.TransitionSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.ViewCompat;

import com.liuyk.main.activity.R;

public class ImageActivity extends AppCompatActivity implements View.OnClickListener, View.OnTouchListener {
    private static final String TAG = "ImageActivity";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail_image);
        init();
    }

    private void init() {
        ImageView image = findViewById(R.id.image);
        image.setOnClickListener(this);
        image.setOnTouchListener(this);
        //1、设置相同的TransitionName
        ViewCompat.setTransitionName(image, "stereoscopic_anim");

        //2、设置WindowTransition,除指定的ShareElement外，其它所有View都会执行这个Transition动画
        getWindow().setEnterTransition(new Fade());
        getWindow().setExitTransition(new Fade());

        //3、设置ShareElementTransition,指定的ShareElement会执行这个Transiton动画
        TransitionSet transitionSet = new TransitionSet();
        transitionSet.addTransition(new ChangeBounds());
        transitionSet.addTransition(new ChangeTransform());
        transitionSet.addTarget(image);
        getWindow().setSharedElementEnterTransition(transitionSet);
        getWindow().setSharedElementExitTransition(transitionSet);
    }

    @Override
    public void onClick(View v) {
        Log.e(TAG, "click");
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Log.e(TAG, event.getAction() + "");
        return false;
    }
}
